from wtforms import Form,validators,widgets
from wtforms.fields import simple
from wtforms import widgets
import os

#-------表单----------
class DownloadForm(Form):
    """下载表单"""
    filename = simple.StringField(
        label="电影名称",
        # widget=widgets.TextInput(),
        description="电影名称",
        render_kw={
            "class":"form-control input",
            "placeholder":"请输入电影名称！",
            "onfocus":"this.select();",
            "autocomplete":"off",
            "style":"width:70%;position:relative;height:20px;font-size:small;font-weight: 400;",
        }
    )
    fileurl = simple.StringField(
        label="下载链接",
        validators=[
            validators.DataRequired(message="请输入链接！")
        ],
        description="URL",
        render_kw={
            "class":"form-control input",
            "onfocus":"this.select();",
            "placeholder":"请输入链接！",
            "autocomplete":"off",
            "style":"width:70%;position:relative;height:20px;font-size:small;font-weight: 400;float: left;",
        }
    )
    filepath = simple.StringField(
        label="保存路径",
        description="保存路径",
        widget=widgets.TextArea(),
        render_kw={
            "class":"form-control",
            "onfocus":"this.select();",
            "placeholder":"选填",
            "autocomplete":"off",
            "style":"width:70%;position:relative;right:-10px;height:20px;font-size:small;font-weight: 400;",
        }
    )
    savepath = simple.StringField(
        label='保存路径',
        description='保存路径',
        widget=widgets.TextInput(),
        render_kw={
            "class": "form-control input",
            "placeholder": "请输入保存路径",
            "onfocus": "this.select();",
            "autocomplete": "off",
            "value":"%s"%os.path.expanduser('~\Downloads'),
            "style": "width:70%;position:relative;height:20px;font-size:small;font-weight: 400;",
        }

    )
    submit = simple.SubmitField(
        label="新增",
        render_kw={
            "id":"new_download",
            "class": "btn btn btn-success btn-block",
            "onclick":"download()",
            "style":"width:80px;height:23px;position:relative;margin-top:3px;padding: 0;display:inline-block;color:#fff;background-color:#8ca86d;font-weight:13px;text-align:center;border-radius:2px;",
        }
    )